#!/usr/bin/env python

# --------------------------------------
# projects/python/4primes/TestPrimes.py
# Copyright (C) 2009
# Glenn P. Downing
# --------------------------------------

# To run the tests
#     TestPrimes.py

# To document the tests
#     pydoc -w TestPrimes

import main
import unittest

# ----------
# TestReader
# ----------

class TestReader (object) :
    def __init__ (self, s) :
        self.s = s

    def read (self) :
        return self.s

# ----------
# TestWriter
# ----------

class TestWriter (object) :
    def str (self) :
        return self.s

    def write (self, *a) :
        self.s = str(a[0])
        for w in a[1:] :
            self.s += ' '
            self.s += str(w)
        self.s += '\n'

# -----------
# TestPrimes
# -----------

class TestPrimes (unittest.TestCase) :
    # ----
    # read
    # ----

    def test_read (self) :
        reader = TestReader('10000\n')
        main.my_read(reader)
        self.assert_(main.i ==  10000)

    # ----
    # eval
    # ----

    def test_eval1 (self) :
        main.i =  1
        main.my_eval()
        self.assert_(main.j < 0)

    def test_eval2 (self) :
        main.i = 100
        main.my_eval()
        self.assert_(main.j == 2)

    def test_eval3 (self) :
        main.i = 201
        main.my_eval()
        self.assert_(main.m == 193)

    def test_eval4 (self) :
        main.i =  900
        main.my_eval()
        self.assert_(main.z == 13)
    
    def test_eval5 (self) :
        main.i = 29
        main.my_eval()
        self.assert_(main.v == 3)
        
    def test_eval6 (self) :
        main.i =  99000
        main.my_eval()
        self.assert_(main.z == 98993)
    
    def test_eval7 (self) :
        main.i = 9991234
        main.my_eval()
        self.assert_(main.z ==9991211)

    # -----
    # print
    # -----

    def test_print (self) :
        main.i =  1
	main.j = -1
        writer = TestWriter()
        main.my_print(writer)
        self.assert_(writer.str() == "Impossible\n")

if __name__ == "__main__" :
    unittest.main()
